<!-- 项目工时 -->
<template>
  <el-descriptions :column="3" size="large">
    <el-descriptions-item label-class-name="right-align" label='项目名称'>
      <span class="text--info subtext">{{projectInfo.projectName}}</span>
    </el-descriptions-item>

    <el-descriptions-item label-class-name="right-align" label='项目编号'>
      <span class="text--info subtext">{{projectInfo.projectCode}}</span>
    </el-descriptions-item>

    <el-descriptions-item label-class-name="right-align" label='填报月份'>
      <span class="text--info subtext">{{projectInfo?.fillMonth}}</span>
    </el-descriptions-item>

    <el-descriptions-item label-class-name="right-align hour-text" label='项目工时'>
      <div class="work-tips">
        <div>
          <span class="left">填报人数</span>
          <span>{{projectInfo.totalPerson}}</span>
        </div>
        <div class="total">
          <span class="left">工时总计</span>
          <span>{{projectInfo.totalHour}}</span>
        </div>
        <p>注：人员列表与项目成员一致</p>
      </div>

      <el-skeleton style="height: 50vh" :rows="8" :loading="loading" animated>
        <el-table
          :data="projectInfo?.detailList"
          border
          style="width: 100%"
          v-loading="loading"
          :header-cell-style="{ background: '#eef1f6', color: '#606266' }"
        >
          <template #empty>
            <el-empty :image-size="150" description="暂无数据"></el-empty>
          </template>

          <el-table-column type="index" label="序号" width="60">
            <template v-slot="scope">
              <span>{{
                (pageNum - 1) * pageSize +
                scope.$index + 1
              }}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="userName"
            label="姓名"
          ></el-table-column>
          <el-table-column
            prop="belongOrg"
            label="所属单位"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop="quantity"
            label="工时"
            show-overflow-tooltip
          ></el-table-column>
        </el-table>
      </el-skeleton>
    </el-descriptions-item>
  </el-descriptions>
</template>

<script lang="ts" setup>
import { onMounted, ref, watch } from "vue";
import {useRoute } from "vue-router";
import {workingHourDetails} from "/@/api/project";
import { cloneDeep } from "lodash-es";
const props = defineProps({
  projectInfo: {
    type: Object
  },
});
const loading = ref<boolean>(false);
const route = useRoute();
const projectInfo = ref({});
const pageSize = 10;
const pageNum = 1;
watch(
  () => props.projectInfo,
  newvalue => {
    projectInfo.value = newvalue;
  },
  { immediate: true }
);

onMounted(() => {
  projectInfo.value = props.projectInfo;
});

const initWorkingHourDetails = async () => {
  loading.value = true;
  try {
    const id = route.query.id;
    const { code, data } = await workingHourDetails({ id:id });
    if (code === 200) {
      const copyFormData = cloneDeep(data);
      projectInfo.value = copyFormData;
    }
  } catch (err) {
    console.log(err);
  } finally {
    loading.value = false;
  }
};
initWorkingHourDetails()
</script>

<style lang="scss" scoped>
  .work-tips{
    display:flex;
    align-items: center;
    margin-bottom: 10px;;
    color:#999;
    .total{
      margin:0 30px;
    }
    .left{
      margin-right: 4px;
    }
  }
  :deep .hour-text{
    display: block;
    margin-bottom: 10px;
  }
</style>
